//leetcode 20
public class Lt20 {
    public boolean invalid(String s){
        //{[()]}
        ArrayStack stack=new ArrayStack<String>();

        //定义三种括号，({[ 压入栈中
        for (int lp=0;lp < s.length();lp++) {
            char sChar=s.charAt(lp);
            if(sChar=='{'||sChar=='['||sChar=='('){
                stack.push(sChar);
            }else{
               char topChar=(char) stack.pop();
               if(sChar=='}'&&topChar!='{'){
                return false;
               }
               if(sChar==']'&&topChar!='['){
                return false;
               }
               if(sChar==')'&&topChar!='('){
                return false;
               }
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Lt20 lt20=new Lt20();
        System.out.println(lt20.invalid("({[[]})"));
    }
}